var DeviceSound = function(container,playerID,type) {
	this.container = container;
	this.playerID = playerID;
	this.applianceType = "";
	this.soundFile = "";
	this.volume = 0;
	this.muted = false;
	switch (type)
	{
		case "vacuumcleaner":
			this.applianceType = 'vacuumcleaner';
			this.soundFile = "OGG/vacuumcleaner-quiet.ogg";
			break;
		case "dishwasher":
			this.applianceType = 'dishwasher';
			this.soundFile = "OGG/dishwasher.ogg";
			break;
		case "blowdryer":
			this.applianceType = 'blowdryer';
			this.soundFile = "OGG/blowdryer-quiet.ogg";
		default:
			break;
	}
	
	this.audioElt = document.createElement('audio');
	this.audioElt.setAttribute('id',this.playerID);
	this.audioElt.setAttribute('type','audio/ogg');
	this.audioElt.setAttribute('preload','auto');
	this.audioElt.setAttribute('autobuffer','true');
	this.audioElt.setAttribute('loop','true');
	var src = document.createElement('source');
	src.setAttribute('src',this.soundFile);
	this.audioElt.appendChild(src);
	this.container.appendChild(this.audioElt);
	
	this.audioElt.addEventListener('ended', function(){ this.currentTime = 0; }, false);
	
	this.decrementVolume = function() {
		if (this.volume > .5)
		{
			setTimeout(function(thisObj) { 
				thisObj.volume = thisObj.volume-.05;
				/*if (!thisObj.muted)
				{
					thisObj.audioElt.volume = thisObj.volume;
				}*/
				//thisObj.audioElt.volume = thisObj.audioElt.volume-.05;
				thisObj.decrementVolume();
			},40,this);
		}
	}
	
	this.turnOn = function() {
		this.volume = 1;
		if (!this.muted)
		{
			this.audioElt.volume = this.volume;
		}
		this.audioElt.play();
		setTimeout(function(thisObj) { 
			thisObj.decrementVolume();
			}, 5000, this);
	};
	
	this.turnOff = function() {
		this.audioElt.pause();
		this.audioElt.currentTime = 0;
	};
	
	this.mute = function() {
		this.muted = true;
		this.audioElt.volume = 0;
	};
	
	this.unmute = function() {
		this.muted = false;
		this.audioElt.volume = this.volume;
	};
}


